package utils

import (
	"crypto/md5"
	"encoding/hex"
	"os"
	"path"
	"strconv"
	"time"
)

func ExecMkdirs(source string) error {
	return os.MkdirAll(source, os.ModePerm)
}
func GetGernate() string {
	seed := time.Now().UnixNano()
	text := strconv.FormatInt(seed, 10)
	ctx := md5.New()
	ctx.Write([]byte(text))
	return hex.EncodeToString(ctx.Sum(nil))
}

func GetExt(fileName string) string {
	return path.Ext(fileName)
}
func DelFile(source string) error {
	_, er := os.Stat(source)
	if er != nil {
		if os.IsNotExist(er) {
			return nil
		} else {
			return er
		}
	}
	return os.Remove(source)
}
